package controller;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import service.ChatClientService;
import dto.Account;
import dto.Message;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.SwingUtilities;
import service.*;
import view.ChatWindow;

public class ChatClientServiceImpl extends UnicastRemoteObject implements ChatClientService {

    private ClientController client;
    private Account account;

    protected ChatClientServiceImpl() throws RemoteException {
    }

    @Override
    public void reciveMessage(Message message, ChatRoomInt cs) {
        client.reciveMessage(message, cs);
    }

    
    public void reciveBuzz(ChatRoomInt cs) throws RemoteException {
        client.reciveBuzz(cs);
        
    }

    /*
     * this method for file info
     */

    @Override
    public void receive_file_imfo(Message message, ChatRoomInt cs) {
        client.reciveFileInfo(message, cs);
    }

    @Override
    /**
     * announce method gets announcements from server Then Show it.
     */
    public void announce(String Announcement) {
        client.setAnnouncement(Announcement);
    }

    @Override
    public void notifyState(Account account) {
        client.notifyState(account);
    }

    @Override
    /**
     * getLoggedInAccount: return Account corresponding to the that Clientservice
     */
    public Account getLoggedInAccount() {
        return account;
    }
    /**
     * setClient: set the ClientController.
     */
    public void setClient(ClientController client) {
        this.client = client;
    }

    @Override
    /**
     * friendRequest: to tell user that he/she got a friend request.
     */
    public void friendRequest(Account senderAccount) {

        client.friendRequest(senderAccount);
    }

    @Override
    /**
     * friendRequestReply : to tell user that he/she got a friend request reply.
     */
    public void friendRequestReply(Account userWhoReply, int reply) {
        client.friendRequestReply(userWhoReply, reply);
    }

    @Override
    /**
     * set the Account corresponding to that client Service.
     */
    public void setAccount(Account a) throws RemoteException {

        account = a;
    }

    @Override
    public void terminateAbnormaly() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                client.closeAll();
            }
        });
    }
        
    @Override
    public void updateMembersList(Account account,ChatRoomInt room) throws RemoteException {
        client.updateMembersList(account,room);
    }
    
     public void addToMemberList(Account account,ChatRoomInt room)throws RemoteException{
     
       client.addToMemberList(account, room);  
     
     }

}
